package com.vogue.supplymall.shop.common;

import com.vogue.supplymall.common.domain.dto.SearchInfo;

/**
 * The type Check search info utils.
 *
 * @aouthor: zhangliang
 * @date: Create in 2017-12-22
 */
public class CheckSearchInfoUtils {

    /**
     * Apply boolean.
     * 检索信息的通用check
     * 有一个检查失败返回true
     *
     * @param searchInfo the search info
     * @return the boolean
     */
    public static Boolean apply(SearchInfo searchInfo) {
        return commonCheck(searchInfo);
    }

    private static Boolean commonCheck(SearchInfo searchInfo) {
        // failed return true
        return isEmpty(searchInfo) || checkLimit(searchInfo);
    }

    private static Boolean isEmpty(SearchInfo searchInfo) {
        // null return true
        return null == searchInfo;
    }

    private static Boolean checkLimit(SearchInfo searchInfo) {
        // error return true
        return searchInfo.getStart() < 0 || searchInfo.getLength() < 0;
    }
}
